package com.yuncheng.spcyApi.controller;

import com.yuncheng.spcyApi.alog.annotation.Log;
import com.yuncheng.spcyApi.spcyService.SysMenuService;
import com.yuncheng.vo.HttpResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;


@Api(tags = "权限菜单-接口")
@RestController
@RequestMapping(value = "/api/spzx-spcy/menu")
public class SysMenuController {

    @Resource
    private SysMenuService sysMenuService;

    @Log(title = "查询用户顶级权限菜单")
    @ApiOperation(value = "查询用户顶级权限菜单")
    @GetMapping(value = "queryTopMenuList")
    public HttpResult queryTopMenuList(){

        return HttpResult.ok(sysMenuService.queryTopMenuList(null));
    }

    @Log(title = "查询用户顶级权限菜单-根据部门id")
    @ApiOperation(value = "查询用户顶级权限菜单-根据部门id")
    @GetMapping(value = "queryTopMenuListByOrg")
    public HttpResult queryTopMenuListByOrg(@RequestParam(value = "id",defaultValue = "")String id){

        return HttpResult.ok(sysMenuService.queryTopMenuList(id));
    }

    @Log(title = "查询用户所有权限菜单列表")
    @ApiOperation(value = "查询用户所有权限菜单列表")
    @GetMapping(value = "queryAllMenuList")
    public HttpResult queryAllMenuList(){

        return HttpResult.ok(sysMenuService.queryAllMenuList());
    }

    @Log(title = "查询用户对应的子菜单列表")
    @ApiOperation(value = "查询用户对应的子菜单列表")
    @GetMapping(value = "queryTopChildrenMenuList")
    public HttpResult queryTopChildrenMenuList(@RequestParam(value = "id",defaultValue = "") String id){

        return HttpResult.ok(sysMenuService.queryTopChildrenMenuList(id));
    }


    @Log(title = "查询用户当前菜单下的所有子列表")
    @ApiOperation(value = "查询用户当前菜单下的所有子列表")
    @GetMapping(value = "queryChildrenMList")
    public HttpResult queryChildrenMList(@RequestParam(value = "id",defaultValue = "") String id){

        return HttpResult.ok(sysMenuService.queryChildrenMList(id));
    }

    @Log(title = "验证当前菜单下是否存在权限")
    @ApiOperation(value = "验证当前菜单下是否存在权限")
    @GetMapping(value = "verifyAuth")
    public HttpResult verifyAuth(@RequestParam(value = "id",defaultValue = "") String id){
        boolean flag = sysMenuService.verifyAuth(id);
        if (!flag){
            return HttpResult.error("当前菜单没有权限，请联系管理员进行授权！");
        }

        return HttpResult.ok();
    }


}
